class Solution:
    def reverse(self, x: int) -> int:
        s=str(x)
        
        if x<0:
            x=int(s[len(s):0:-1])*-1
            if x<=(1<<31)*-1:
                return 0
            else:
                return x
        else:
            x=int(s[::-1])
            if x>=(1<<31)-1:
                return 0
            else:
                return x